package com.pj.project.sys_points_history;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.project.sys_user.SysUser;
import com.pj.project.sys_user.SysUserMapper;
import com.pj.project.sys_user.SysUserService;
import com.pj.project.sys_user_sync.brd.SspServerBrdUtil;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: sys_user -- 用户表
 * @author shengzhang 
 */
@RestController
@RequestMapping("/SysPointHistory/")
public class SysPointHistoryController {

	/** 底层 Mapper 对象 */
	@Autowired
    SysUserMapper sysUserMapper;

	/** 底层 Service 对象 */
	@Autowired
    SysUserService sysUserService;

	/** 底层 Service 对象 */
	@Autowired
    SysPointHistoryMapper sysPointHistoryMapper;


	/** 增 */  
	@RequestMapping("add")
	@SaCheckPermission(SysPointHistory.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson add(SysUser s){
		// 新增 
		SysUser s2 = sysUserService.add(s);
		
		// $$ 向外广播
		SspServerBrdUtil.userAdd(s2, s.getPassword2());
		
		//  返回 
		return AjaxJson.getSuccessData(s2);
	}


	/** 改 */
	@RequestMapping("update")
	@SaCheckPermission(SysPointHistory.PERMISSION_CODE)
	@Transactional(rollbackFor = Exception.class)
	public AjaxJson update(SysUser s){
		// 修改
		SysUser s2 = sysUserService.update(s);

		// $$ 向外广播
		SspServerBrdUtil.userUpdate(s2);

		//  返回
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
	@SaCheckPermission(SysPointHistory.PERMISSION_CODE)
	public AjaxJson getById(Long id){
		SysUser s = sysUserMapper.getById(id);
		return AjaxJson.getSuccessData(s);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	@RequestMapping("getList")
	@SaCheckPermission(SysPointHistory.PERMISSION_CODE)
	public AjaxJson getList() { 
		SoMap so = SoMap.getRequestSoMap();
		so.setByNull("isDel", 1);
		List<SysPointHistory> list = sysPointHistoryMapper.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}
	
}
